const _tslib = require('tslib');
const _util = require('@antv/util');

import editorStyle from '../utils/defaultStyle';

const taskDefaultOptions = {
    icon: null,
    iconStyle: {
        width: 12,
        height: 12,
        left: 2,
        top: 2,
    },
    style: {
        ...editorStyle.nodeStyle,
        fill: '#E7F7FE',
        stroke: '#1890FF',
        cursor: 'default',
    },
    stateStyles: {
        selected: {
            fill: '#95D6FB',
        },
        hover: {
            cursor: editorStyle.cursor.hoverNode,
        },
    },
};

export default function(G6) {
    G6.registerNode(
        'normal',
        {
            shapeType: 'rect',
            options: {
                size: [200, 40],
                style: {
                    stroke: '#9ED5F8',
                    test: 'normal.options.style',
                    radius: 5,
                    fill: 'rgba(0,0,0,0.5)',
                },
            },
            getShapeStyle(cfg) {
                var defaultStyle = this.getOptions(cfg).style;
                var strokeStyle = {
                    stroke: cfg.color,
                }; // 如果设置了color，则覆盖默认的stroke属性
                var style = (0, _util.mix)({}, defaultStyle, strokeStyle);
                var size = this.getSize(cfg);
                var width = style.width || size[0];
                var height = style.height || size[1];
                var styles = (0, _tslib.__assign)(
                    {
                        x: -width / 2,
                        y: -height / 2,
                        width: width,
                        height: height,
                    },
                    style
                );
                return styles;
            },
        },
        'base-node'
    );

    G6.registerNode(
        'task-node',
        {
            shapeType: 'rect',
            options: {
                ...taskDefaultOptions,
            },
            getShapeStyle(cfg) {
                cfg.size = [80, 44];
                const width = cfg.size[0];
                const height = cfg.size[1];
                const style = {
                    x: 0 - width / 2,
                    y: 0 - height / 2,
                    width,
                    height,
                    ...this.options.style,
                };
                return style;
            },
        },
        'base-node'
    );

    //
    G6.registerNode(
        'success',
        {
            style: {
                stroke: '#8BCDF7',
            },
            labelCfg: {
                offset: 8,
            },
            preRect: {
                fill: '#1C9BEC',
            },
            stateIcon: {
                show: true,
                img: require('../icon/succ.svg'),
            },
        },
        'base-node'
    );
}
